package main.request;

import java.io.IOException;

import utils.Debug;
import main.process.FtpRequest;


public class RequestQuit implements ProcessRequestInterface {
	
	private static class SingletonHolder
	{		
		/** Instance unique non préinitialisée */
		private final static RequestQuit instance = new RequestQuit();
	}
	
	public static RequestQuit getInstance()
	{
		return SingletonHolder.instance;
	}

	@Override
	public void processRequest(String[] request, FtpRequest ftp) throws IOException {
		
		Debug.debug(this.getClass().getName(), request, ftp.getDebug());
		
		
		if(!request[0].equals("QUIT"))
		{
			next(request, ftp);
		}
		else {
		try {
			ftp.write("231 Bye\n");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		ftp.setConnectedFalse();
		
		}
	}

	@Override
	public void next(String[] request, FtpRequest ftp) throws IOException {
		RequestRetr.getInstance().processRequest(request, ftp);

	}
	
}
